package kin.test;

import java.io.IOException;

import org.antlr.runtime.tree.TreeAdaptor;
import org.apache.poi.ss.formula.functions.T;

import kin.json.CustomerDeserializer;
import kin.json.MyBeanDeserializerModifier;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.deser.BeanDeserializerFactory;
import com.fasterxml.jackson.databind.deser.DeserializerFactory;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class t3 {
public static void main(String[] args) {
	String json="{\"us_id\":1,\"aaa\":null,\"children\":[5,6,7],\"parent\":3,\"mo\":2}";
	
	JsonFactory jf= new JsonFactory();
	ObjectMapper mapper = new ObjectMapper();
	
	try {
		JsonParser jp=jf.createParser(json);
		//mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE,  true);

		// mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY , true);
		// mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT , true);
		 mapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY , true);
		// DeserializationFeature.
		// mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING , true);
		 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES ,false);
		 //this.configure(Feature., false);
		// DeserializerFactory df=BeanDeserializerFactory.instance;
		// df.withDeserializerModifier(new MyBeanDeserializerModifier());
		//JsonNodeFactory jnf= mapper.getNodeFactory();
		 SimpleModule module =
			      new SimpleModule();
		 
			   // module.addDeserializer(Long.class, new LongJsonDeserializer());
			    module.setDeserializerModifier(new MyBeanDeserializerModifier());
			 
			 
			    mapper.registerModule(module);
			 
			    Us uu=mapper.readValue(json, Us.class);
			    //TypeReference<Object> t=new TypeReference<Object>(){};
			//module.registerSubtypes(subtypes);
			   //ObjectReader or=mapper.readValue(json, t);
			//System.out.println("or:"+or);
			    System.out.println("id:"+uu.getUs_id());
			    System.out.println("id:"+uu.getMo());
		 //mapper.getDeserializationConfig().with(new MyBeanDeserializerModifier());
		
	} catch (JsonParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
	

	
}
}
